<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>我的资料 - My Profile</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/statics/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/statics/style/admin.css}" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的资料</div>
                <div class="layui-card-body" pad15>

                    <div class="layui-form" lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userName" th:value="${user.userName}" readonly class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="nickName" th:value="${user.nickName}" lay-verify="nickname"
                                       autocomplete="off" placeholder="请输入昵称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">头像</label>
                            <div class="layui-input-inline">
                                <input type="text" name="avatar" lay-verify="required" placeholder="请上传图片" autocomplete="off"
                                       class="layui-input" th:value="${user.avatar}"/>
                            </div>
                            <button style="float: left;" type="button" class="layui-btn" id="layuiadmin-upload-useradmin">上传图片</button>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">手机</label>
                            <div class="layui-input-inline">
                                <input type="text" name="mobile" th:value="${user.mobile}" lay-verify="phone"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="email" th:value="${user.email}" lay-verify="email"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input name="id" type="hidden" th:value="${user.id}" />
                                <input name="state" type="hidden" th:value="${user.state}"/>
                                <input name="roleId" type="hidden" th:value="${user.roleId}"/>
                                <button class="layui-btn" lay-submit="" id="LAY-profile-form-submit" lay-filter="LAY-profile-form-submit">确认修改</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/statics/layui/layui.js}"></script>
<script th:inline="none">
    layui.config({
        base: '/statics/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function () {
        var $ = layui.$
            , form = layui.form
            , upload = layui.upload;

        upload.render({
            elem: '#layuiadmin-upload-useradmin'
            , url: '/api/file/local/upload'
            , accept: 'images'
            , method: 'post'
            , acceptMime: 'image/*'
            , before: function () {
                layer.load(1,{shade: 0.8});
            }
            , done: function (res) {
                layer.closeAll();
                $(this.item).prev("div").children("input").val(res.data);
                layer.msg('图片上传成功!',{icon:1,time:1000});
            }
        });

        form.on('submit(LAY-profile-form-submit)', function(data){
            $.ajax({
                url: '/api/user/edit',
                method: 'post',
                data: data.field,
                dataType:'JSON',
                async: true,
                success:function(result){
                    if(result.code=='0'){
                        layer.msg('保存成功!',{icon:1,time:1000});
                    }else {
                        layer.msg('保存失败！' + result.msg, {icon: 2, time: 1000});
                    }
                },
                error:function (err) {
                    layer.msg('保存失败！', {icon: 2, time: 1000});
                }
            });
            return false;
        });
    });
</script>
</body>
</html>